<!-- TrainSubmitUserInfo.html -->
<!DOCTYPE html>
<html class="base_gary_bg_color">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>查看/修改个人信息</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/base.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css"/>
		<style type="text/css" media="screen">
			.base_right_item {
				color: white;
			}
			.right_aligned_input {
				text-align: right;
			}
			a:active {
				color: #d9d9d9;
			}
			.mui-btn-blue {
				border: 1px solid #18b4ed;
				background-color: #18b4ed;
			}
		</style>
	</head>
	<body class="base_gary_bg_color">
		<div class="base_style_color" id='BarAppearance' style="height: 22px;width: 100%; position:fixed; left: 0px;top:0px;"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar" style="position: fixed;left: 0px;top: 20px;">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>我的资料</span>
			<a class="base_right_item" href="#" onclick="submitClick()"> 提交 </a>
		</div>
		<div class="base_content_div base_content_font"  >
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label class="base_grey">姓名</label>
					<input id="username" class="right_aligned_input base_content_font base_dark_grey" type="text" placeholder="请输入您的姓名" >
				</div>
				<div class="mui-input-row">
					<label class="base_grey">昵称</label>
					<input id="rname" class="right_aligned_input base_content_font base_dark_grey" type="text" placeholder="请输入您的昵称">
				</div>
				<div class="mui-input-row">
					<label class="base_grey">性别</label>
					<input id="user_sex" class="right_aligned_input base_content_font base_dark_grey" type="text" value="" placeholder="请选择性别" readonly>
				</div>
				<div class="mui-input-row">
					<label class="base_grey">出生年份</label>
					<input id="user_birthday" class="time_input right_aligned_input base_content_font base_dark_grey" type="number" placeholder="请选择出生年份" value="" data-options='' readonly>
				</div>
				<div class="mui-input-row">
					<label class="base_grey">QQ</label>
					<input id="qqnumber" class="right_aligned_input base_content_font base_dark_grey" type="tel" placeholder="请输入您的QQ号" maxlength="15">
				</div>
				<div class="mui-input-row">
					<label class="base_grey">手机号码</label>
					<input id="phonenumber" class="right_aligned_input base_content_font base_dark_grey" type="tel" placeholder="请输入您的联系电话" maxlength="11" onkeyup="this.value=this.value.replace(/\D/g,'')">
				</div>
				<div class="mui-input-row">
					<label class="base_grey">专业名称</label>
					<input id="professional" class="right_aligned_input base_content_font base_dark_grey" type="text" value="" placeholder="请输入您的专业名称" >
				</div>
				<div class="mui-input-row">
					<label class="base_grey">所在学校</label>
					<input id="school" class="time_input right_aligned_input base_content_font base_dark_grey" type="text" placeholder="请输入您的所在学校"  >
				</div>
				<div class="mui-input-row">
					<label class="base_grey">所在年级</label>
					<input id="grade" class="right_aligned_input base_content_font base_dark_grey" type="text" placeholder="请输入您的所在的年级"  readonly >
				</div>
				<div class="mui-input-row">
					<label class="base_grey">选择身份</label>
					<input id="usertype" class="right_aligned_input base_content_font base_dark_grey" type="text" placeholder="请选择身份" readonly>
				</div>
			</form>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/jquery-weui.min.js"></script>
	<script type="text/javascript" src="../../script/mui.min.js"></script>
	<script type="text/javascript" src="../../script/mui.dtpicker.js"></script>
	<script type="text/javascript" src="../../script/mui.picker.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript">
	
		apiready = function() {
			setupData();
			customUI();
		}
		function setupData() {
			showProgress();
			var params = {
				uid : $api.getStorage('cfnetppuid'),
			};
			//			 alert("params=="+JSON.stringify(params))
			cfnetppPOST(applstOne, params, true, function(data, status) {
				if (status == 'success') {
					if (data.code == 200) {
						var jsonData = data.json;
						setupUserData(jsonData);
					} else {
					}
				} else {
				}
			});
		}

		function setupUserData(data) {
		   $('#rname').val(data.rname);
			$('#username').val(data.username);
			$('#user_sex').val(data.usersex == 1 ? '男' : '女');
			$('#user_birthday').val(data.birthday);
			$('#qqnumber').val(data.qqnumber);
			$('#phonenumber').val(data.telephone);
			$('#professional').val(data.professional);//专业名称
			$('#school').val(data.school);//学校名称
			$('#grade').val(data.grade);//所在年级
			var usertype = data.usertype;
			var usertypename = '';
			if (usertype == 0) {//学生
				usertypename = '我是学生';
			} else if (usertype == 1) {//老师
				usertypename = '我是老师';
			} else if (usertype == 2) {//企业人员
				usertypename = '我是企业人员';
			}
			$('#usertype').val(usertypename);
			//			$('#shixi_start').val(timeStringWithTimeStamp(data.starttime));
			//			$('#shixi_end').val(timeStringWithTimeStamp(data.endtime));
		}


		$(document).ready(function() {
			customUI();
		});
		function customUI() {
			setupSexPicker();
			setupYearPicker();
			setupUserTypePicker();
			setupGradePicker();
		}

		//设置QQ号输入限制
		function setupQQ() {
		}

		function setupSexPicker() {
			$("#user_sex").picker({
				title : "请选择性别",
				cols : [{
					textAlign : 'center',
					values : ['男', '女']
				}],
				onChange : function(p, v, dv) {
					console.log('p:' + p, 'v:' + v, 'dv' + dv);
				},
				onClose : function(p, v, d) {
					console.log("close");
				}
			});
		}
			function setupGradePicker() {
			$("#grade").picker({
				title : "请选择年级",
				cols : [{
					textAlign : 'center',
					values : ['一年级', '二年级','三年级','四年级',]
				}],
				onChange : function(p, v, dv) {
					console.log('p:' + p, 'v:' + v, 'dv' + dv);
				},
				onClose : function(p, v, d) {
					console.log("close");
				}
			});
		}
		//用户角色
		function setupUserTypePicker() {
			$("#usertype").picker({
				title : "请选择身份",
				cols : [{
					textAlign : 'center',
					values : ['我是学生', '我是老师','我是企业人员']
				}],
				onChange : function(p, v, dv) {
					console.log('p:' + p, 'v:' + v, 'dv' + dv);
				},
				onClose : function(p, v, d) {
					console.log("close");
				}
			});
		}

		function setupYearPicker() {
			var now = new Date();
			var nowYear = now.getFullYear();
			var minYear = 1900;
			var yearArr = new Array();
			for (var i = 0; i <= nowYear - minYear; i++) {
				yearArr.push(nowYear - i);
			}
			$('#user_birthday').picker({
				title : "请选择出生年份",
				cols : [{
					textAlign : 'center',
					values : yearArr
				}],
				onChange : function(p, v, dv) {
					console.log('p:' + p, 'v:' + v, 'dv' + dv);
				},
				onClose : function(p, v, d) {
					console.log("close");
				}
			});
		}

		function backClick() {
			api.closeWin();
		}

		function submitClick() {
			var rname = $('#rname').val();
			var username = $('#username').val();
			var  professional = $('#professional').val();
			var telephone = $('#phonenumber').val();
			var qqnumber = $('#qqnumber').val();
			var usersex = $('#user_sex').val();
			var birthday = $('#user_birthday').val();
			var school = $('#school').val();
			var grade = $('#grade').val();
			var usertype = $('#usertype').val();
			if (telephone.length != 11) {
				api.toast({
					msg : '手机号不正确',
					duration : 2000,
					location : 'bottom'
				});
				return;
			}
			if (usersex.length <= 0||usertype.length <= 0 || birthday.length <= 0) {
				api.toast({
					msg : '请完善信息后再提交',
					duration : 2000,
					location : 'bottom'
				});
				return;
			}
			var usertypes = '';
			if (usertype == '我是学生') {//学生
				usertypes = 0;
			} else if (usertype == '我是老师') {//老师
				usertypes = 1;
			} else if (usertype == '我是企业人员') {//企业人员
				usertypes = 2;
			}
			var usexType = usersex == '男' ? 1 : 0;
			api.showProgress({
				style : 'default',
				animationType : 'fade',
				title : '正在提交',
				text : '请稍候...',
				modal : true
			});
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				rname: rname,//昵称
                username:username,//真实姓名
                professional:professional,//专业名称
                usersex: usexType,//性别
                birthday:  birthday,//出生年份
                telephone:  telephone,
                qqnumber: qqnumber,
                school: school,//学校名称
                grade: grade,//所在的年级
                usertype: usertypes,//用户角色 0：学生 1：老师，
			};
			//			 alert("params=="+JSON.stringify(params))
			cfnetppPOST(editactOne, params, true, function(data, status) {
				api.hideProgress();
				//				alert("提交"+JSON.stringify(data));
				if (status == 'success') {
					if (data.code == 200) {
						api.toast({
							msg : '提交成功',
							duration : 2000,
							location : 'bottom'
						});
						setTimeout(function() {
							backClick();
						}, 1000);
					} else {
						api.toast({
							msg : '提交失败，请重试',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '提交失败，请检查网络',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}
	</script>
</html>
